package com.lc.rongzecaifu.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.rongzecaifu.MyApplication;
import com.lc.rongzecaifu.conn.JsonBanklist;
import com.lc.rongzecaifu.rongzecaifu.R;
import com.zcx.helper.bound.BoundViewHelper;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 3/7/2016.
 */
public class BankListAdapter2 extends RecyclerView.Adapter<BankListAdapter2.ViewHolder> {

    private Context context;
    private List<JsonBanklist.Info.ListContent> list;
    private OnItemClickListener onItemClickListener;

    public BankListAdapter2(Context context, List<JsonBanklist.Info.ListContent> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = BoundViewHelper.boundView(this, MyApplication.scaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_17_item_view, null)));

        ViewHolder vh = new ViewHolder(view);

        return vh;
    }


    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {

        holder.tvName.setText(list.get(position).bank_name);

//        Log.e(list.get(position).bank_name, "-----------------------------");

        holder.ivLogo.setImageURI(Uri.parse(list.get(position).bank_ico));

        holder.itemView.setTag(list.get(position));

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                onItemClickListener.onClick(position);

            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setOnItemCliclListener(OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    public interface OnItemClickListener {

        void onClick(int position);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        @Bind(R.id.iv_logo) ImageView ivLogo;
        @Bind(R.id.tv_name) TextView tvName;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }


}
